package cn.com.majiang.controller;

import cn.com.majiang.enums.ResultCode;
import cn.com.majiang.param.RoomInfoParam;
import cn.com.majiang.result.BaseResult;
import cn.com.majiang.service.IRoomService;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 房间管理
 * Created by jiangyanxin on 2017/5/10.
 */

@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/room")
public class RoomController {
    Logger logger = LoggerFactory.getLogger(RoomController.class);

    @Autowired
    private IRoomService roomService;
    /**
     * 搜索房间列表
     *
     * @throws Exception
     */
    @RequestMapping(value = "/searchRoomList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public BaseResult searchRoomList(String str, HttpServletRequest request) throws Exception {
        logger.info("搜索房间列表入参:{}", str);
        if (StringUtils.isBlank(str)) {
            return BaseResult.build(ResultCode.NULL_REQUESTPARAM);
        }
        RoomInfoParam args = JSON.parseObject(str, RoomInfoParam.class);
      //  Integer id = (Integer) request.getSession().getAttribute("id");
        //if (id == 1) {
            logger.info("表明是管理员");
            Map<String, Object> result = roomService.searchRoomList(args);
            return BaseResult.build(result);
        //} else {
            //return BaseResult.build(ResultCode.REQUEST_FAIL);
       // }
    }
}
